package cqut.wys.classloader;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;

/**
 * --------神兽出没--------/
 *   ┌─┐     ┌─┐
 * ┌─┘─┴─────┘─┴─┐
 * │      ─      │
 * │  ┬─┘   └─┬  │
 * │             │
 * │      ┴      │  Code is far away from bug with the animal protecting
 * └───┐      ┌──┘  神兽保佑,代码无bug
 *     │      │
 *     │      └──────┐
 *     │             ├┐
 *     │             ┌┘
 *     └┐ ┐ ┌───┬─┐ ┌┘
 *      │ ┤ ┤   │ ┤ ┤
 *      └─┴─┘   └─┴─┘
 * --------感觉萌萌哒--------/
 *
 * @author wuyoushan
 * @date 2018/5/17
 */
public class Test {
    public static void main(String[] args) throws Exception {
        ClassPool pool = ClassPool.getDefault();
        CtClass cc = pool.get("cqut.wys.classloader.Hello");
        CtMethod m = cc.getDeclaredMethod("say");
        m.insertBefore("System.out.println(\"Hello.say():\");");
        Class c = cc.toClass();
        Hello h = (Hello) c.newInstance();
        h.say();
    }
}
